package com.sap.apitest2.deprecated.client;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;

import com.sap.apitest2.deprecated.service.IService;


public class ProfileGroupTest extends AbstractTest implements IService {
	  public static void main(String args[]) throws Exception {
	        
	    	//testRequestJsonGetProfileGroups();
		    testRequestJsonPutProfileGroup();
	    	//testRequestJsonGetProfileGroup();
	    	//testRequestJsonPutProfileGroup();
	    	//testRequestJsonRemoveProfileGroup();
	    	
	        System.out.println("\n"); 
	        System.exit(0); 
	    }
		private static void testRequestJsonGetProfileGroups()throws Exception{
	    	System.out.println("\n");
	        System.out.println("Sent HTTP GET request to get profile groups info, expect JSON");
	        GetMethod get = new GetMethod(getTestHost()+ACTION_PROFILEGROUPS);
	        get.addRequestHeader("Accept" , "application/json");
	        HttpClient httpclient = new HttpClient();
	       
	        try {
	            int result = httpclient.executeMethod(get); 
	            System.out.println("Response status code: " + result);
	            System.out.println("Response body: ");
	            System.out.println(get.getResponseBodyAsString());
	        } finally {
	            get.releaseConnection();             
	        }
	    }
		private static void testRequestJsonGetProfileGroup()throws Exception{
	    	System.out.println("\n");
	        System.out.println("Sent HTTP GET request to get single profile group info, expect JSON");
	        GetMethod get = new GetMethod(getTestHost()+ACTION_PROFILEGROUP+"/2");
	        get.addRequestHeader("Accept" , "application/json");
	        HttpClient httpclient = new HttpClient();
	       
	        try {
	            int result = httpclient.executeMethod(get); 
	            System.out.println("Response status code: " + result);
	            System.out.println("Response body: ");
	            System.out.println(get.getResponseBodyAsString());
	        } finally {
	            get.releaseConnection();             
	        }
	    }
	    private static void testRequestJsonPutProfileGroup()throws Exception{
	    	System.out.println("\n");
	        System.out.println("Sent HTTP POST request to save profile group info, use JSON, expect RESPONSE");
	        PutMethod post = new PutMethod(getTestHost()+ACTION_SAVEPROFILEGROUP+"/0");
	        post.addRequestHeader("Accept" , "application/json");
	        HttpClient httpclient = new HttpClient();

	        try {
	        	
	        	
	        	post.setRequestEntity(new StringRequestEntity(
	        	       	" {\"ProfileGroup\":[{\"id\":0,\"name\":\"DEMO1\",\"type\":1}]}"));

	            int result = httpclient.executeMethod(post);
	            
	            System.out.println("Response status code: " + result);
	            System.out.println("Response body: ");
	            System.out.println(post.getResponseBodyAsString());
	        } finally {
	            post.releaseConnection();            
	        }
	    }

	    private static void testRequestJsonRemoveProfileGroup()throws Exception{
	    	System.out.println("\n");
	        System.out.println("Sent HTTP POST request to remove profile group, use JSON, expect RESPONSE");
	        DeleteMethod post = new DeleteMethod(getTestHost()+ACTION_REMOVEPROFILEGROUP+"/1");
	        post.addRequestHeader("Accept" , "application/json");
	        HttpClient httpclient = new HttpClient();

	        try {
	        	
	            int result = httpclient.executeMethod(post);
	            
	            System.out.println("Response status code: " + result);
	            System.out.println("Response body: ");
	            System.out.println(post.getResponseBodyAsString());
	        } finally {
	            post.releaseConnection();            
	        }
	    }
}
